<script>
	import Vue from 'vue'
	var basic = require('@/pages/Common/basic.js');
	export default {
		globalData: {
			adminPath: 'https://dexinhebei.com/api',
			adminFontPath: 'https://dexinhebei.com',
			adminImgPath: 'https://dexinhebei.com',
			loginLogo: '',
			loadingImg: '',
			tabBarInfo: [
				{
					title: "首页",
					url: "/pages/Home/index",
					iconPath: "/static/tabBar/home_def.png",
					selectedIconPath: "/static/tabBar/home_sel.png",
				},
				{
					title: "抢单",
					url: "/pages/Discovery/index",
					iconPath: "/static/tabBar/task_def.png",
					selectedIconPath: "/static/tabBar/task_sel.png",
				},
				{
					title: "消息",
					url: "/pages/Message/index",
					iconPath: "/static/tabBar/message_def.png",
					selectedIconPath: "/static/tabBar/message_sel.png",
				},
				{
					title: "我的",
					url: "/pages/Personal/index",
					iconPath: "/static/tabBar/user_def.png",
					selectedIconPath: "/static/tabBar/user_sel.png",
				}
			],
			openUserInfo: '',
			appStyle: '#ff0000',
			appMode: 'tester',
			appLibrary: '1.9.0', //推荐的基础库支持
			appVision: 108, //版本 
			// #ifdef APP-PLUS
			appPlat: 'APP-PLUS', //运行平台
			// #endif
			// #ifdef H5
			appPlat: 'H5', //运行平台
			// #endif
			// #ifdef MP-WEIXIN
			appPlat: 'MP-WEIXIN', //运行平台
			// #endif
			// #ifdef MP-ALIPAY
			appPlat: 'MP-ALIPAY', //运行平台
			// #endif
			// #ifdef MP-BAIDU
			appPlat: 'MP-BAIDU', //运行平台
			// #endif
			// #ifdef MP-TOUTIAO
			appPlat: 'MP-TOUTIAO', //运行平台
			// #endif
			// #ifdef MP-QQ
			appPlat: 'MP-QQ', //运行平台  
			// #endif
			//图库信息 
			adminImg: {
				path: '', //图库路径
				folder: '', //存储文件夹
			},
			appTheme: {}, //小程序主题风格
			//商家相关信息
			seller: {}, //商家相关信息
			//用户公开信息
			user_openinfo: {},
			// 用户地址信息
			user_address: {
				address_all: [], //所有地址
				address_default: {}, //默认地址
				address_current: {}, //当前选择地址
			},
			// 银行卡信息
			bankcardid:'',
			bankcard: {
				id:'',
				name:'',
				openBankNm:'',
				cardNo:''
			},
			//shopcar相关信息
			shopcarNum: -1, //shopcar显示数量
			shop_cart: [], //shopcar
			total: 0, //总费用
			shopcarStatus: 2, //shopcar状态，2未修改，3已修改
			//大学列表
			agent_list: '',
			default_agent: {}, //大学默认数据
			campus_data: '', //选择校区信息
			min_price: 2,
			money_reward: {
				max_run_fee: "",
				min_run_fee: "",
				list: []
			}, //赏金配置信息
			point_info: '', //校园快递点信息
			mobile: '', //手机号码
			load_img: '',
			share_info: {},
			miniapp_title: '',
			customer_mobile: '',
			service_img: '',
		},
		onLaunch: function() {
			console.log('App Launch')
			// 版本更新
			if (wx.canIUse('getUpdateManager')) {
				const updateManager = wx.getUpdateManager()
				updateManager.onCheckForUpdate(function(res) {
					// 请求完新版本信息的回调
					console.log('是否需要更新：', res.hasUpdate)
					if (res.hasUpdate) {
						updateManager.onUpdateReady(function() {
							wx.showModal({
								title: '更新提示',
								content: '新版本已经准备好，是否重启应用？',
								success: function(res) {
									if (res.confirm) {
										updateManager.applyUpdate()
									}
								}
							})
						})
						updateManager.onUpdateFailed(function() {
							wx.showModal({
								title: '已经有新版本了哟~',
								content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
							})
						})
					}
				})
			} else {
				wx.showModal({
					title: '提示',
					content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
				})
			}
			
			//先判断是否是微信浏览器
			// #ifdef H5
			// var ua = window.navigator.userAgent.toLowerCase();
			// if(ua.match(/MicroMessenger/i)=="micromessenger") {
			//     this.globalData.appPlat = 'MP-WEIXIN-H5'; //微信浏览器运行平台
			// }
			// #endif
			this.loginCkeck();
		},
		onShow: function() {},
		onHide: function() {

		},
		methods: {
			//验证用户是否已经登录
			loginCkeck: function() {
				var that = this;
				//读取本地存储确定是否有用户信息
				try {
					var value = uni.getStorageSync('local_user_session')
					if (value) {
						//获取用户信息后进行相关设置
						that.globalData.openUserInfo = value;
					}
				} catch (e) {
					//读取错误
				}
				//开始请求数据，获取商家的基础设置信息
				that.shopInfo((res) => {
					//先执行onLaunch再执行onload
					if (getCurrentPages().length != 0) {
						getCurrentPages()[getCurrentPages().length - 1].onLoad();
						getCurrentPages()[getCurrentPages().length - 1].onShow();
					}
				});
			},
			//拉取小程序商家信息
			shopInfo(fn) {
				var that = this;
				var path = '/xyb/user/baseinfo';
				var data = {
					appPlat: that.globalData.appPlat
				}
				//判断是否切换了appkey
				if (this.globalData.appFormerKey) {
					//开启加载窗口
					uni.showLoading({
						title: '加载中',
						mask: true
					});
				}
				basic.requestPost(this, path, data, (res) => {
					uni.hideLoading();
					if (res.data.code) {
						//重新设置用户的基础登录标志信息
						// that.globalData.openUserInfo = res.data.trd_session;
						// uni.setStorage('local_user_session', res.data.trd_session);
						//设置商家基本信息和小程序风格信息
						// that.globalData.seller = res.data.system;
						// that.globalData.apply_info = res.data.apply_info;
						// if (res.data.theme.set_theme_color == '#ffffff' || res.data.theme.set_theme_color == '#FFFFFF') {
						// 	that.globalData.appStyle = '#DEDEDE';
						// } else {
						// 	that.globalData.appStyle = res.data.theme.set_theme_color;
						// }

						//设置默认图库服务器信息
						that.globalData.adminImgPath = res.data.data.qiniu_url;
						// that.globalData.adminImg.folder = res.data.img_ser.folder;
						that.globalData.loginLogo = res.data.data.login_logo
						that.globalData.loadingImg = res.data.data.loading

						//设置用户信息 2024.5.30隐藏 移到主页调用
						// if (res.data.data.user_info.nickname) {
						// 	that.globalData.user_openinfo = res.data.data.user_info || {};
						// } else {
						// 	that.globalData.user_openinfo = {};
						// }
						//设置学校信息 取学校列表第一项 作为默认学校
						var agent_list = res.data.data.agent_list;
						var defaultAgent = {};
						defaultAgent.id = agent_list[0].id
						defaultAgent.title = agent_list[0].agent_area
						uni.setStorageSync('default_agent', defaultAgent);
						that.globalData.default_agent = defaultAgent;
						// 设置学校列表
						var temp_agent_list = []
						for (var i = 0; i < agent_list.length; i++) {
							if(agent_list[i].id==uni.getStorageSync('default_agent').id){
								var defaultAgent = {};
								defaultAgent.id = uni.getStorageSync('default_agent').id
								defaultAgent.title = agent_list[i].agent_area
								uni.setStorageSync('default_agent', defaultAgent);
							}
							var temp = {
								title: agent_list[i].agent_area,
								id: agent_list[i].id,
							}
							temp_agent_list.push(temp);
						}
						that.globalData.agent_list = temp_agent_list;
						
						// try {
						// 	var value = uni.getStorageSync('default_agent')
						// 	if (value.id!=undefined) {
						// 		//获取用户信息后进行相关设置 
						// 		that.globalData.default_agent = value;
						// 	} else {
						// 		uni.navigateTo({
						// 			url: "/pages/Component/Module/Campus/Program/school/index/index",
						// 		})
						// 	}
						// } catch (e) {
						// 	try {
						// 		uni.navigateTo({
						// 			url: "/pages/Component/Module/Campus/Program/school/index/index",
						// 		})
						// 	} catch (e) {
						// 		// error
						// 	}
						// 	//读取错误  
						// }
						
						//2024.5.30隐藏 移到主页调用
						// var user_address = res.data.data.user_address_list
						// if (user_address.length) {
						// 	that.globalData.user_address.address_all = ''; //地址数据
						// 	that.globalData.user_address.address_all = user_address; //地址数据
						// 	for (var i = 0; i < user_address.length; i++) {
						// 		if (user_address[i].defaults) {
						// 			that.globalData.user_address.address_default = user_address[i]; //默认地址
						// 			that.globalData.user_address.address_current = user_address[i]; //当前
						// 		}
						// 	} 
						// 	if (that.globalData.user_address.address_default == '') {
						// 		that.globalData.user_address.address_default = user_address[0]; //默认地址
						// 		that.globalData.user_address.address_current = user_address[0]; //当前
						// 	}
						// } else { 
						// 	that.globalData.user_address.address_all = ''; //地址数据
						// 	that.globalData.user_address.address_default = ''; //默认地址
						// 	that.globalData.user_address.address_current = ''; //当前
						// }  
						//手机号码
						that.globalData.mobile = res.data.data.mobile;
						//所有输入金额最小值
						that.globalData.min_price = 0;
						//当前赏金
						that.globalData.money_reward = {
							max_run_fee: res.data.data.max_run_fee,
							min_run_fee: res.data.data.min_run_fee,
							list: res.data.data.run_fee
						}
						//小程序信息
						that.globalData.share_info = {
							share_img: res.data.data.share_img,
							share_title: res.data.data.share_title
						}
						that.globalData.miniapp_title = res.data.data.miniapp_title;
						that.globalData.customer_mobile = res.data.data.customer_mobile;
						that.globalData.service_img = res.data.data.service_img;

						//设置用户地址信息 
						// that.getAddress();
						//设置购物车信息
						// that.globalData.shopcarInfo = res.data.car_info;
						// that.globalData.shopcarNum = Number(res.data.car_info.length);

						//开始设置首页路径
						// that.checkIndexPath(res.data.theme.first_page_id);
						fn(res);
						//先执行onLaunch再执行onload
						// if (getCurrentPages().length != 0) {
						// 	getCurrentPages()[getCurrentPages().length - 1].onLoad();
						// }
					}
				});
			},
			//设置页面整体风格
			setTheme: function() {
				//开始设置菜单tab
			},
			//判断首页的路径信息
			checkIndexPath(index_id) {
				if (index_id == 1) {
					var path = '/pages/Home/index/index';
				} else if (index_id == 2) {
					var path = '/pages/Functions/index/index';
				} else if (index_id == 3) {
					var path = '/pages/Plus/index/index';
				} else if (index_id == 4) {
					var path = '/pages/Discovery/index/index';
				} else if (index_id == 5) {
					var path = '/pages/Personal/index/index';
				}
				this.globalData.appIndex = path;
			},

			//获取用户地址信息
			getAddress(user_address) {

			},
		},
	}
</script>

<style>
/* 全局字体图标和公共样式 */
	@import url("/static/iconfont/iconfont.css");
	@import url("/static/common/common.scss");
	.flex {
		display: flex;
	}
	page{
		background: #F3F3F3;
	}
	.inline-flex {
		display: inline-flex;
	}
	
	.flex-item {
		flex: 1;
		min-width: 0;
	}
	
	.flex-center {
		align-items: center;
		justify-content: center;
	}
	
	.flex-wrap {
		flex-wrap: wrap;
	}
	
	.flex-direction-column {
		display: flex;
		flex-direction: column;
	}
	
	.align-items-center {
		align-items: center;
	}
	
	.align-items-start {
		align-items: flex-start;
	}
	
	.align-items-end {
		align-items: flex-end;
	}
	
	.justify-content-between {
		justify-content: space-between;
	}
	
	.justify-content-around {
		justify-content: space-around;
	}
	
	.justify-content-center {
		justify-content: center;
	}
	
	.justify-content-start {
		justify-content: flex-start;
	}
	
	.justify-content-end {
		justify-content: flex-end;
	}
	
	.wbcentre {
		text-align: center;
	}
	.nav-list {
		display: flex;
		flex-wrap: wrap;
		padding: 0px 40upx 0px;
		justify-content: space-between;
	}

	.nav-li {
		padding: 30upx;
		border-radius: 12upx;
		width: 45%;
		margin: 0 2.5% 40upx;
		background-image: url(https://cdn.nlark.com/yuque/0/2019/png/280374/1552996358352-assets/web-upload/cc3b1807-c684-4b83-8f80-80e5b8a6b975.png);
		background-size: cover;
		background-position: center;
		position: relative;
		z-index: 1;
	}

	.nav-li::after {
		content: '';
		position: absolute;
		z-index: -1;
		background-color: inherit;
		width: 100%;
		height: 100%;
		left: 0;
		bottom: -10%;
		border-radius: 10upx;
		opacity: 0.2;
		transform: scale(0.9, 0.9);
	}

	.nav-li.cur {
		color: #fff;
		background: rgb(94, 185, 94);
		box-shadow: 4upx 4upx 6upx rgba(94, 185, 94, 0.4);
	}

	.nav-title {
		font-size: 32upx;
		font-weight: 300;
	}

	.nav-title::first-letter {
		font-size: 40upx;
		margin-right: 4upx;
	}

	.nav-name {
		font-size: 28upx;
		text-transform: Capitalize;
		margin-top: 20upx;
		position: relative;
	}

	.nav-name::before {
		content: '';
		position: absolute;
		display: block;
		width: 40upx;
		height: 6upx;
		background: #fff;
		bottom: 0;
		right: 0;
		opacity: 0.5;
	}

	.nav-name::after {
		content: '';
		position: absolute;
		display: block;
		width: 100upx;
		height: 1px;
		background: #fff;
		bottom: 0;
		right: 40upx;
		opacity: 0.3;
	}

	.nav-name::first-letter {
		font-weight: bold;
		font-size: 36upx;
		margin-right: 1px;
	}

	.nav-li text {
		position: absolute;
		right: 30upx;
		top: 30upx;
		font-size: 52upx;
		width: 60upx;
		height: 60upx;
		text-align: center;
		line-height: 60upx;
	}

	.text-light {
		font-weight: 300;
	}
	
	.default-height {
		width: 100%;
		height: 92rpx;
		padding-bottom: constant(safe-area-inset-bottom);/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom); /* 兼容 iOS >= 11.2 */
	}
	
	.safe-padding{
		width: 100%;
		padding-bottom: constant(safe-area-inset-bottom);/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom); /* 兼容 iOS >= 11.2 */
	}

	@keyframes show {
		0% {
			transform: translateY(-50px);
		}

		60% {
			transform: translateY(40upx);
		}

		100% {
			transform: translateY(0px);
		}
	}

	@-webkit-keyframes show {
		0% {
			transform: translateY(-50px);
		}

		60% {
			transform: translateY(40upx);
		}

		100% {
			transform: translateY(0px);
		}
	}

	/* colorUI引入css样式 */
	/* 解决头条小程序组件内引入字体不生效的问题 */
	/* #ifdef MP-TOUTIAO */
	@font-face {
		font-family: uniicons;
		src: url('/static/uni.ttf');
	}

	/* #endif */
</style>
